package Lee_code;

/**
 * @author blh
 * @date 2024年07月08日 9:20
 */
public class Lee_74_78 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] sea = new int[m * n];
        int index = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                sea[index++] = matrix[i][j];
            }
        }
        int left = 0, right = m * n - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (sea[mid] == target) {
                return true;
            } else if (sea[mid] > target) {
                right = mid - 1;
            } else if (sea[mid] < target) {
                left = mid + 1;
            }
        }
        return false;
    }
}
